package xyf.p11.other.twopointer;

/**
 * ClassName: P0075_Color
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:22 AM
 * Version: 1.0
 **/
public class P0075_Color
{
    public void sortColors(int[] nums)
    {
        int start = 0;
        int end = nums.length - 1;

        while (start < end)
        {
            if (nums[start] != 2)
            {
                start++;
                continue;
            }
            if (nums[end] != 0)
            {
                end--;
                continue;
            }

            swap(nums, start, end);
        }
    }

    private void swap(int[] nums, int x, int y)
    {
        int tmp = nums[x];
        nums[x] = nums[y];
        nums[y] = tmp;
    }
}
